package com.jrx.anytxn.param.job.bactchBillCompare.bean;

import java.io.Serializable;
import java.nio.file.Paths;

/**
 * 商户号_业务日期_DETAILS.dat
 * 示例：800230763000001_20221124_DETAILS.dat
 *
 */
public class WexinFileNameBean implements Serializable {

    public static final String PATH_SUFFIX = "_DETAILS.dat";

    private static final String PATH_MIDDLE = "repayment";

    /**
     * 文件名称
     */
    private String filename;

    /**
     * 商户号，15位
     */
    private String merchNo;

    /**
     * 业务日期，格式：yyyyMMdd
     */
    private String busDate;

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

    public String getMerchNo() {
        return merchNo;
    }

    public void setMerchNo(String merchNo) {
        this.merchNo = merchNo;
    }

    public String getBusDate() {
        return busDate;
    }

    public void setBusDate(String busDate) {
        this.busDate = busDate;
    }

    /**
     * 获取对账文件在指定日期的所在目录
     * @param parentDir
     * @param thirdChannel
     * @param dateStr
     * @return
     */
    public static String directory(String parentDir, String thirdChannel, String dateStr) {
        return Paths.get(parentDir, thirdChannel, PATH_MIDDLE, dateStr).toString();
    }

    /**
     * 解析一个文件名称并转换为实例
     * @param filename
     * @return
     */
    public static WexinFileNameBean extract(String filename) {
        String[] components = filename.split("_");
        if (filename.endsWith(PATH_SUFFIX) && components.length >= 3) {
            WexinFileNameBean bean = new WexinFileNameBean();
            bean.setMerchNo(components[0]);
            bean.setBusDate(components[1]);
            bean.setFilename(filename);
            return bean;
        }

        return null;
    }

}
